package cz.muni.fi.pa165.sme.ws;

import java.net.MalformedURLException;
import java.net.URL;

import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import cz.muni.fi.pa165.sportmanager.burnedcaloriesws.BurnedCaloriesWS;
import cz.muni.fi.pa165.sportmanager.sportactivityws.SportActivityWS;
import org.springframework.stereotype.Component;

/**
 * @author jirankova
 */
@Component
public class EndpointManager {

	private BurnedCaloriesWS burnedCaloriesWS;
	private SportActivityWS sportActivityWS;

	@PostConstruct
	public void init() {

		try {
			final URL calories = new URL("http://localhost:8080/pa165/ws/BurnedCaloriesWS.wsdl");
			final URL activities = new URL("http://localhost:8080/pa165/ws/SportActivityWS.wsdl");

			final QName caloriesName = new QName("http://muni.cz/fi/pa165/sportManager/burnedCaloriesWS", "BurnedCaloriesWSService");
			final QName activitiesName = new QName("http://muni.cz/fi/pa165/sportManager/sportActivityWS", "SportActivityWSService");

			final Service caloriesService = Service.create(calories, caloriesName);
			final Service activitiesService = Service.create(activities, activitiesName);

			burnedCaloriesWS = caloriesService.getPort(BurnedCaloriesWS.class);
			sportActivityWS = activitiesService.getPort(SportActivityWS.class);

		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}

	public BurnedCaloriesWS getBurnedCaloriesWS() {
		return burnedCaloriesWS;
	}

	public SportActivityWS getSportActivityWS() {
		return sportActivityWS;
	}
}
